Skip to content

Implement feature flag system#1823

Open
paustint wants to merge 1 commit into
mainfrom
feat/add-feature-flags
Open

Implement feature flag system#1823
paustint wants to merge 1 commit into
mainfrom
feat/add-feature-flags

Conversation

@paustint

Copy link
Copy Markdown
Contributor

Introduce a feature flag system that allows for client-side verification and database support for user and team-specific overrides. This system enhances feature management by enabling dynamic control over feature availability based on user entitlements.

Copilot AI review requested due to automatic review settings June 23, 2026 03:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a lightweight, code-defined feature flag registry with database-backed per-user/per-team overrides, plus server-side signing and browser-side signature verification so the UI can consume “trusted” resolved flags.

Changes:

  • Add FeatureFlagOverride Prisma model + migration to persist user/team-scoped flag overrides.
  • Introduce shared @jetstream/types flag registry + deterministic serialization for signing/verification.
  • Resolve + sign flags in the API /api/me profile path, verify once on the client, and consume flags via new Jotai state/hook (with an example UI gate in AppHome).

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
prisma/schema.prisma Adds FeatureFlagOverride model and relations on User/Team.
prisma/migrations/20260623031854_add_feature_flag_override/migration.sql Creates the feature_flag_override table and indexes/FKs.
libs/types/src/lib/types.ts Extends UserProfileUi with featureFlags + featureFlagsSignature.
libs/types/src/lib/feature-flags.ts Adds shared feature flag registry + stable signing serialization.
libs/types/src/index.ts Re-exports feature flag utilities/types.
libs/shared/ui-utils/src/lib/shared-feature-flag-utils.ts Adds browser-side signature verification and extraction of trusted flags.
libs/shared/ui-utils/src/index.ts Exports the new UI feature flag helper.
libs/shared/ui-core/src/app/AppHome/AppHome.tsx Adds feature-flag gating for home cards.
libs/shared/ui-app-state/src/lib/ui-app-state.ts Verifies flags once during profile fetch; adds featureFlagsState + useFeatureFlag.
libs/api-config/src/lib/env-config.ts Adds JETSTREAM_FEATURE_FLAG_PRIVATE_KEY env support.
apps/api/src/app/services/feature-flag-signing.service.ts Implements ECDSA P-256 signing (ieee-p1363) for resolved flags.
apps/api/src/app/services/tests/feature-flag-signing.service.spec.ts Tests signature validity and tamper detection.
apps/api/src/app/db/user.db.ts Resolves + signs flags when building the user-facing profile.
apps/api/src/app/db/feature-flags.db.ts Adds DB-backed flag resolution + optional authoritative server-side gate helper.
apps/api/src/app/db/tests/feature-flags.db.spec.ts Tests resolution behavior, scoping, and gating.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread libs/shared/ui-utils/src/lib/shared-feature-flag-utils.ts
Comment thread libs/shared/ui-utils/src/lib/shared-feature-flag-utils.ts Outdated
Comment thread apps/api/src/app/db/feature-flags.db.ts Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 5 comments.

Comment thread libs/shared/ui-core/src/app/AppHome/AppHome.tsx
Comment thread libs/shared/ui-utils/src/lib/shared-feature-flag-utils.ts
Comment thread libs/shared/ui-utils/src/lib/shared-feature-flag-utils.ts
Comment thread libs/api-config/src/lib/env-config.ts
Comment thread apps/api/src/app/db/user.db.ts

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.

Comment on lines +39 to +42
export function serializeFeatureFlagsForSigning(userId: string, flags: FeatureFlags): string {
const entries = [...ALL_FEATURE_FLAG_KEYS].sort().map((key) => [key, !!flags[key]] as const);
return JSON.stringify({ userId, flags: entries });
}
Comment on lines +54 to +56
const key = await crypto.subtle.importKey('spki', getPublicKeyDer(), { name: 'ECDSA', namedCurve: 'P-256' }, false, ['verify']);
const payload = encodeUtf8(serializeFeatureFlagsForSigning(profile.id, received));
const isValid = await crypto.subtle.verify({ name: 'ECDSA', hash: 'SHA-256' }, key, base64ToBytes(signature), payload);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants